package com.sky.demo.service.impl;

import java.util.List;
import java.util.Map;

import org.realogic.btp.sequence.KSequenceGenerator;
import org.realogic.cfm.domain.KPageResult;
import org.realogic.cfm.persistence.query.QueryCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageInfo;
import com.sky.demo.entity.EntityItem;
import com.sky.demo.repository.EntityItemDao;
import com.sky.demo.service.EntityItemService;

/**
 * @see EntityItemService
 */
@Service("entityItemService")
public class EntityItemServiceImpl implements EntityItemService {

	// private Log log = LogFactory.getLog(getClass());

	private EntityItemDao entityItemDao;

	public EntityItemServiceImpl() {

	}

	public EntityItemDao getEntityItemDao() {
		return entityItemDao;
	}

	@Autowired
	public void setEntityItemDao(EntityItemDao entityItemDao) {
		this.entityItemDao = entityItemDao;
	}

	// @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public int create(final EntityItem aModel) {
		aModel.setId(KSequenceGenerator.uuidOfLang());
		return entityItemDao.create(aModel);
	}

	// @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public int update(final EntityItem aModel) {
		return entityItemDao.update(aModel);
	}

	// @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public int remove(final Long aKey) {
		return entityItemDao.remove(aKey);
	}

	public EntityItem read(final Long aKey) {
		return entityItemDao.read(aKey);
	}

	public KPageResult query(QueryCondition aCondition) {
		List<EntityItem> tmpList = entityItemDao.query(aCondition);
		KPageResult temp = null;
		if (tmpList != null) {
			temp = new KPageResult(tmpList, aCondition.getTotalSize(), aCondition.getPageNo(), aCondition.getPageSize());
		}
		return temp;
	}

	public PageInfo<EntityItem> query(Map<String, Object> aCondition, int aPageNo, int aPageSize) {
		return entityItemDao.query(aCondition, aPageNo, aPageSize);
	}

	public int create(List<EntityItem> aModelList) {
		return entityItemDao.create(aModelList);
	}

	public int update(List<EntityItem> aModelList) {
		return entityItemDao.update(aModelList);
	}

	public int remove(List<EntityItem> aModelList) {
		return entityItemDao.remove(aModelList);
	}

	public int deleteByMasterPK(Long aKey) {
		return entityItemDao.deleteByMasterPK(aKey);
	}

	public List<EntityItem> loadByMasterPK(Long aKey) {
		return entityItemDao.loadByMasterPK(aKey);
	}
}